What is react-simple-animate?
react-simple-animate is a lightweight animation library for React that allows you to easily add animations to your components. It provides a simple API to animate elements with various effects such as transitions, keyframes, and more.
What are react-simple-animate's main functionalities?
Transition Animation
This feature allows you to animate the transition of an element's properties from a start state to an end state. In this example, the opacity of the div element transitions from 0 to 1, creating a fade-in effect.
```jsx
import React from 'react';
import { Animate } from 'react-simple-animate';
const TransitionExample = () => (
<Animate
play
duration={1}
start={{ opacity: 0 }}
end={{ opacity: 1 }}
>
<div>Fade In</div>
</Animate>
);
export default TransitionExample;
```
Keyframe Animation
This feature allows you to define keyframe animations, where you can specify multiple steps of an animation. In this example, the div element slides 100px to the right and then back to its original position.
```jsx
import React from 'react';
import { AnimateKeyframes } from 'react-simple-animate';
const KeyframeExample = () => (
<AnimateKeyframes
play
duration={2}
keyframes={[
{ 0: { transform: 'translateX(0)' } },
{ 50: { transform: 'translateX(100px)' } },
{ 100: { transform: 'translateX(0)' } }
]}
>
<div>Slide</div>
</AnimateKeyframes>
);
export default KeyframeExample;
```
CSS Animation
This feature allows you to use CSS animations within the AnimateGroup component. In this example, a div element with a bounce animation is created using CSS keyframes.
```jsx
import React from 'react';
import { AnimateGroup } from 'react-simple-animate';
const CSSAnimationExample = () => (
<AnimateGroup play>
<div className="box" style={{ animation: 'bounce 2s infinite' }}>Bounce</div>
</AnimateGroup>
);
export default CSSAnimationExample;
// CSS
@keyframes bounce {
0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
40% { transform: translateY(-30px); }
60% { transform: translateY(-15px); }
}
.box {
width: 100px;
height: 100px;
background-color: red;
}
```
Other packages similar to react-simple-animate
react-spring
react-spring is a spring-physics-based animation library for React. It provides more advanced and flexible animations compared to react-simple-animate, allowing for complex animations and interactions. It is highly performant and can handle a wide range of animation scenarios.
framer-motion
framer-motion is a powerful animation library for React that offers a wide range of features including gestures, layout animations, and more. It is more feature-rich compared to react-simple-animate and is suitable for creating complex animations and interactions.
react-transition-group
react-transition-group is a low-level animation library for React that provides more control over the transition states of components. It is more flexible but requires more setup compared to react-simple-animate, making it suitable for developers who need fine-grained control over animations.
Make web animation simple :clap:
Features:
- Simple animation from inline style A to style B
- Support add and remove child (New)
- Make animation toggle easy
- In-built delay animation mechanism
- Tiny size without other dependency
Install
$ yarn add react-simple-animate
or
$ npm install react-simple-animate -S
Example
Check out the interactive demo. 😍
Navigate into example
folder and install
$ yarn && yarn start
or
$ npm install && npm run start
Screenshot of the example app below
Quick start
The following example demonstrate animate individual or array of components. React simple animate will take
cares component will mount and unmount.
import react from 'react';
import Animate from 'react-simple-animate';
import YourComponent from './YourComponent';
const props = {
startAnimation: true,
startStyle: { opacity: 0 }
endStyle={ opacity: 1 }
};
export default function SexyComponent(props) {
return <div>
// Animate individual component or components
<Animate {...props}>
<h1>React simple animate</h1>
<YourComponent>
</Animate>
// Animate components with add/remove, style will inherit from parent Animate props
<Animate animateOnAddRemove>
{props.componentsArray.map((key) => <Animate {...props}>
<YourComponent key={key}>
</Animate>}
</Animate>
</div>;
}
API
Prop | Type | Required | Description |
---|
startAnimation | boolean | ✓ | Defaults to false. Set to true to start the animation. |
children | node | | Child component to be animated. |
render | Function | | Element animation attributes as argument eg. (attributes) => <div {...attributes} /> |
startStyle | string | | Component initial inline style. |
endStyle | string | ✓ | Component transition to inline style. |
animateOnAddRemove | boolean | | Enable animation on component add and remove. |
onCompleteStyle | string | | Style to be applied after the animation is completed. |
durationSeconds | number | | How long the animation takes in seconds. |
delaySeconds | number | | How much delay should apply before animation starts. |
reverseDelaySeconds | number | | How much delay should apply when reverse/toggle animation. |
onComplete | function | | Call back function after animation complete. |
easeType | string | | Easing type refer to http://easings.net/ |
className | string | | To specify a CSS class. |
Reference
https://medium.com/jsdownunder/react-ui-animation-made-simple-c2ff98056659